/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.corticon.client.util;

import java.io.File;
import java.net.MalformedURLException;
import java.util.Iterator;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

/**
 *
 * @author heweiya
 */
public class CorticonConfig {

    private static String XMLPath = "corticon.xml";  
    public String GetXMLValue(String arrributeName) {

        Document doc = GetXMLFile();
        Iterator it = doc.getRootElement().elementIterator();       
        Element subElem;
        while (it.hasNext()) {
            subElem = (Element) it.next();// son
            if (subElem.getName().trim().equals(arrributeName)) {
                return subElem.getStringValue();
            }
        }
        return null;
    }
   
    public Document GetXMLFile() {
        SAXReader reader = new SAXReader();
        Document doc = null;
        //String CurPath = System.getProperty("user.dir") + "/src";
        String CurPath = this.getClass().getResource("/").getPath();
        try {
            doc = reader.read(new File(CurPath + "/" + XMLPath));
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        return doc;
    }
}
